<template>
	<view class="">
		<!--  -->
		<navBar :title="title"></navBar>
		<!--  -->
		<view class="margin">
			<!--  -->
			<u-gap></u-gap>
			<view class="">
				<u-row :gutter="10">
					<u-col :span="12">
						<uni-data-select placeholder="异常数据" v-model="value" :style="style" :localdata="range"
							@change="changeType"></uni-data-select>
					</u-col>
				</u-row>
				<u-gap></u-gap>
				<u-row :gutter="10">
					<u-col :span="12">
						<uni-data-select placeholder="全部数据" v-model="value1" :style="style" :localdata="range1"
							@change="changeStatus"></uni-data-select>
					</u-col>
				</u-row>
			</view>
			<u-gap></u-gap>
			<!-- 2 -->
			<view class="list">
				<view class="item mt-10" v-for="(val,i) in list" :key="i">
					<uni-card :is-shadow="false" is-full>
						<!--  -->
						<u-row>
							<u-col :span="8">
								<view class="time text-xl">
									{{val.createTime}}
								</view>
							</u-col>
							<u-col :span="4">
								<u-text lines="1" :text="val.deviceName">
								</u-text>
							</u-col>
						</u-row>
						<!--  -->
						<view class="my-10 line">

						</view>

						<!--  -->
						<u-row gutter="20" class="mt-10">
							<u-col :span="4">
								<image @click="detailHandle(val)" src="/static/logo.png"
									style="width: 212rpx;height: 214rpx;" mode="heightFix">
								</image>
							</u-col>
							<u-col :span="1">
							</u-col>
							<u-col :span="7" class="">
								<view class="flex" v-if="val.landscapeBucketName">
									<h4 class="pr-5">
										子设备名称
									</h4>
									<u-text lines="2" :text="val.landscapeBucketName">
									</u-text>
								</view>
								<view class="flex">
									<h4 class="pr-5">
										警告信息
									</h4>
									<u-text lines="2" :text="val.remark">
									</u-text>
								</view>
								<view class="flex ">
									<h4 class="pr-5">
										处理时间
									</h4>
									<view class="">
										{{val.dealTime || '— — — '}}
									</view>
								</view>
								<u-row>
									<u-col :span="7">

									</u-col>
									<u-col :span="5">
										<!--    -->
										<!-- flase  hideen -->
										<button class="" v-if="val.dealUserId == null" type="primary" size="mini"
											@click="dealHandle(val)">处理</button>
									</u-col>
								</u-row>
							</u-col>
						</u-row>
					</uni-card>
				</view>
			</view>

		</view>
		<!--  -->
	</view>
</template>

<script>
	import {
		detailMain,
		dealErroMain,
		ListMain,
		errListMain
	} from '@/api/errorMain/errorMain.js'
	import {
		detailAssist,
		dealErrorAssist,
		ListAssist,
		errorListAssist
	} from '@/api/errorAssist/errorAssist.js'
	export default {
		data() {
			return {
				title: "设备报警",
				style: {
					backgroundColor: "#fff"
				},
				/*  */
				value: '',
				range: [{
						value: 1,
						text: "主设备异常数据"
					},
					{
						value: 0,
						text: "景观桶异常数据"
					},
				],
				/*  */
				value1: '',
				range1: [{
						value: 1,
						text: "主设备全部数据"
					},
					{
						value: 0,
						text: "景观桶全部数据"
					},
				],
				/*  */
				list: [],
				form: {
					pageNum: 1,
					pageSize: 5
				},
				total: 0
			};
		},
		methods: {
			async detailHandle(e) {
				console.log(e);
				if (e.deviceAlarmid) {
					let re = await detailMain(e.deviceAlarmid)
					let oData = re.data
					let {
						dealBy,
						remark
					} = oData
					this.$pub.go(`/pages/warnning/detail/detail?dealBy=${dealBy}&remark=${remark}`)
				}
				if (e.id) {
					let re = await detailAssist(e.id)
					let oData = re.data
					let {
						dealBy,
						remark
					} = oData
					this.$pub.go(`/pages/warnning/detail/detail?dealBy=${dealBy}&remark=${remark}`)
				}
			},
			dealHandle(e) {
				console.log(e, "e");
				uni.showModal({
					title: '提示',
					content: '确定要处理吗？',
					success: async function(res) {
						if (res.confirm) {
							if (e.deviceAlarmid) {
								await dealErroMain(e.deviceAlarmid)
							}
							if (e.id) {
								await dealErrorAssist(e.id)
							}
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},

			async changeType(e) {
				console.log(e, "e");
				if (e == 1) {
					let re = await errListMain(this.form)
					this.list = re.rows
					this.total = re.total
				} else {
					let re = await errorListAssist(this.form)
					this.list = re.rows
					this.total = re.total
				}
			},
			async changeStatus(e) {
				console.log(e, "e");
				if (e == 1) {
					console.log('主正常');
					let re = await ListMain(this.form)
					this.list = re.rows
					this.total = re.total
				} else {
					console.log('辅助正常');
					let re = await ListAssist(this.form)
					this.list = re.rows
					this.total = re.total
				}
			},

		},
		onShow() {
			this.changeType(0)
		},
	}
</script>

<style lang="scss" scoped>
	.index {}
</style>
<style>
	page {
		background-color: #f3f3f3;
	}
</style>